<template>
  <k-view class="statistics-block">
    <k-view class="statistics-title">
      <k-text class="statistics-title-text">{{ statistcsTypeTitle }}得分情况</k-text>
      <k-text class="statistics-title-subtext" v-if="statistcsType === 2"
        >更新时间: {{ getCurrentDate() }}</k-text
      >
      <k-text class="statistics-title-subtext" v-else
        >更新时间: {{ changeStringIntoDate(statisticsData.report_date) }} 每季度更新</k-text
      >
    </k-view>
    <reload-view v-if="isEmpty || isLoading" :loading="isLoading" @reload="reload"> </reload-view>
    <k-view class="statistics-content" v-else>
      <score-diagnosis-read
        :scoreInfo="statisticsData"
        :modelValue="activeScoreTab"
        :diagnosisInfo="diagnosisInfo"
        :chartType="chartType"
        :evaluateInfo="evaluateInfo"
        :chartDataParam="chartDataParam"
      ></score-diagnosis-read>
    </k-view>
  </k-view>
</template>

<script>
import ScoreDiagnosisRead from '@/components/StockDiagnosis/scoreDiagnosis.vue';
import { changeStringIntoDate, formatChgString, getCurrentDate } from '@/utils/index';
import reloadView from '@/components/Home/rankReload.vue';

const defaultSingleSysSore = {
  company_num: 0,
  high_score_num: 0,
  higher_avg_num: 0,
  higher_avg_rate: 0,
  highest_score: 0,
  market_company_num: 0,
  market_score_avg: 0,
  minimum_score: 0,
  report_date: '20220930',
  score_avg: 0,
  score_inc: 0,
  score_inc_rate: 0,
};

export default {
  props: {
    isEmpty: {
      type: Boolean,
      default: false,
    },
    isLoading: {
      type: Boolean,
      default: false,
    },
    statistcsType: {
      type: Number,
      default: '',
    },
    chartData: {
      type: Array,
      default: [],
    },
    statisticsData: {
      type: Object,
      default: defaultSingleSysSore,
    },
    currentIndustry: {
      type: Object,
      default: () => {
        return {
          code: '',
          label: '',
          value: '',
        };
      },
    },
    evaluateInfo: {
      type: Object,
      default: () => {
        return {
          score: 0,
          market_score_avg: 0,
          score_rate: 0,
        };
      },
    },
  },
  components: {
    reloadView,
    ScoreDiagnosisRead,
  },
  data() {
    return {
      activeScoreTab: 0,
    };
  },
  methods: {
    changeStringIntoDate,
    getCurrentDate,
    reload() {
      this.$emit('reload');
    },
  },
  computed: {
    // 统计图表位置的类型，line为折线图，tag为标签图
    chartType() {
      if (this.statistcsType === 1) {
        return 'line';
      } else if (this.statistcsType === 2) {
        return 'tag';
      } else if (this.statistcsType === 3) {
        return 'line';
      } else {
        return 'line';
      }
    },
    chartDataParam() {
      if (this.statistcsType === 1) {
        return {
          block_type: 'all_market',
          block_code: '',
        };
      } else if (this.statistcsType === 2) {
        return {
          block_type: 'stock',
          block_code: '',
        };
      } else if (this.statistcsType === 3) {
        return {
          block_type: 'industry',
          block_code: this.currentIndustry.code,
        };
      } else {
        return {
          block_type: 'region',
          block_code: this.currentIndustry.code,
        };
      }
    },
    statistcsTypeTitle() {
      if (this.statistcsType === 1) {
        return '市场';
      } else if (this.statistcsType === 2) {
        return '自选股';
      } else if (this.statistcsType === 3) {
        return this.currentIndustry.label;
      } else {
        return this.currentIndustry.label;
      }
    },
    diagnosisInfo() {
      const staData = this.statisticsData;
      if (this.statistcsType === 1) {
        return {
          scoreTitle: '健康平均分',
          readArtical: `数据显示，截止${changeStringIntoDate(
            staData.report_date
          )}，国内共计${formatChgString(
            staData.company_num
          )}家上市公司，健康度均分${formatChgString(staData.score_avg, 2)}，较上一周期${
            staData.score_inc < 0 ? '下降' : '增长'
          }约${formatChgString(
            staData.score_inc,
            2
          )}分，80分以上健康得分的公司超过${formatChgString(
            staData.high_score_num
          )}家，整体市场环境稳定向好。`,
        };
      } else if (this.statistcsType === 2) {
        return {
          scoreTitle: '自选平均分',
          readArtical: `数据显示，截止${changeStringIntoDate(staData.report_date)}，您共有自选股${
            staData.company_num || '--'
          }只，其中有健康指数的上市公司，健康指数均分${formatChgString(
            staData.score_avg,
            2
          )}，其中最高分为${formatChgString(staData.highest_score, 2)}，最低分为${formatChgString(
            staData.minimum_score,
            2
          )}，自选股整体得分${
            staData.score_avg > staData.market_score_avg ? '高于' : '低于'
          }市场平均分，${
            staData.score_avg > staData.market_score_avg ? '请继续保持' : '需要关注'
          }！`,
        };
      } else if (this.statistcsType === 3) {
        return {
          scoreTitle: '行业平均分',
          readArtical: `数据显示，${this.statistcsTypeTitle}综合健康指数平均水平为${formatChgString(
            staData.score_avg,
            2
          )}，${
            staData.score_avg < staData.market_score_avg ? '低于' : '高于'
          }全市场平均水平；该行业${formatChgString(
            staData.company_num
          )}家公司中，高于市场平均值的有${formatChgString(
            staData.higher_avg_num
          )}家，占总数的${formatChgString(
            staData.higher_avg_rate,
            2
          )}%，其中最高分${formatChgString(staData.highest_score, 2)}。`,
        };
      } else {
        return {
          scoreTitle: '地区平均分',
          readArtical: `数据显示，${this.statistcsTypeTitle}综合健康指数平均水平为${formatChgString(
            staData.score_avg,
            2
          )}，${
            staData.score_avg < staData.market_score_avg ? '低于' : '高于'
          }全市场平均水平；该地区${formatChgString(
            staData.company_num
          )}家公司中，高于市场平均值的有${formatChgString(
            staData.higher_avg_num
          )}家，占总数的${formatChgString(
            staData.higher_avg_rate,
            2
          )}%，其中最高分${formatChgString(staData.highest_score, 2)}。`,
        };
      }
    },
  },
};
</script>

<style lang="less">
.statistics-block {
  width: 100%;
  background-color: #ffffff;
  border-radius: 16px;
  padding: 20px;
  .statistics-title {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    .statistics-title-text {
      font-size: 36px;
      color: #262626;
      font-weight: 500;
      line-height: 50px;
    }
    .statistics-title-subtext {
      color: rgba(0, 0, 0, 0.4);
      font-size: 24px;
      line-height: 32px;
      font-weight: 400;
    }
  }
}

[theme-mode='black'] {
  .statistics-block {
    background-color: #1c1c1c;
    .statistics-title-text {
      color: rgba(255, 255, 255, 0.84);
    }
    .statistics-title-subtext {
      color: rgba(255, 255, 255, 0.4);
    }
  }
}
</style>
